package com.shaozi.nc.io.mq;

import org.apache.log4j.Logger;

import com.shaozi.data.mq.protocol.ConnectionBuilder;
import com.shaozi.data.mq.protocol.amqp.AMQPTextProducer;
import com.shaozi.nc.data.model.PushMsgModel;
import com.shaozi.utils.common.BeanUtils;
import com.shaozi.utils.data.ObjUtils;

public class PushMsgProducer extends AMQPTextProducer {

	private static final Logger logger = Logger.getLogger(PushMsgProducer.class);

	public PushMsgProducer() {
		super(null);
	}

	public void pushMsg(PushMsgModel model) {
		if (model == null) {
			return;
		}
		ConnectionBuilder connBuilder = (ConnectionBuilder) BeanUtils.getBean("amqpConnBuilder");
		if (connBuilder == null) {
			logger.warn("get mq connBuilder fail");
			return;
		}
		setConnBuilder(connBuilder);

		PushMsgModel ret = (PushMsgModel) ObjUtils.deepCopy(model);
		if (ret == null) {
			logger.warn("deepCopy fail:" + model.toJsonStr());
			return;
		}
		removeUnRetField(ret);
		sendObj("com.push.msg", ret);

	}

	private void removeUnRetField(PushMsgModel model) {
		// 设置空后，转成json字符串不包含
		model.setDelTime(null);
		model.setIsDel(null);
		model.setCreateTime(null);
		model.setPushTimeRegex(null);
	}

}
